package ru.ifmo.rybakov.muclumon;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Property entity describes the single property registered in database.
 * Properties are usually registered in database in constructor using
 * {@link PropertyManager}. If the property already exists it is not created.
 * Property entity only describes the name and the type of property but
 * doesn't store any value. All the values of properties are strored using
 * {@link PropertyValue} entity beans.
 * 
 * @author gleb.rybakov
 */
@Entity
@Table(name = "property")
public class Property {
	@Id
	@GeneratedValue
	private Integer id;
	
	private String name;
	
	private String title;

	protected Property() {} 
	
	public Property(String name) {
		this.name = name;
	}
	
	/**
	 * Constructs and registers property by its identifier and name. Property
	 * can not be registered twice or more times.
	 * @param id Non-null property identifier
	 * @param name Non-null property name
	 */
//	public Property(Integer id, String name, String title) {
//		assert id != null;
//		assert name != null;
//		this.id = id;
//		this.name = name;
//		this.title = title;
////		PropertyManager.getInstance().bind(this);
//	}
	
	/**
	 * Returns the id
	 * @return The id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * Sets the id value
	 * @param id The id to be set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * Returns the name
	 * @return The name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the name value
	 * @param name The name to be set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Property && id != null) {
			return id.equals(((Property) obj).id);
		}
		return super.equals(obj);
	}
	
	

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return id;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	
}
